import { useState } from "react";
import { makeFacade, RoomFacade } from "@/facade/roomFacade";
import { Assistant, HDLevel, LiveStream } from "@/models/LiveRoom";
import { useObservable } from '@/utils/rxHelpers';

type RoomDataHookTuple = [
  RoomFacade,
  string,
  number,
  number,
  string,
  string,
  Assistant[],
  LiveStream[],
  LiveStream[],
  boolean,
  boolean,
  boolean,
  HDLevel,
  number,
  string,
  number,
];

//需要在页面用到的变量都在这里hook，主要用于简化页面调用逻辑和代码
export function useRoomDataFacade(): RoomDataHookTuple {
  const [roomFacade] = useState(() => makeFacade());
  const [roomRole] = useObservable(roomFacade.roomRole$, "");
  const [roomStatus] = useObservable(roomFacade.status$, 0);
  const [type] = useObservable(roomFacade.type$, 2);
  const [ownerId] = useObservable(roomFacade.ownerId$, "");
  const [anchorId] = useObservable(roomFacade.anchorId$, "");
  const [liveStreams] = useObservable(roomFacade.liveStreams$, []);
  const [linkStreams] = useObservable(roomFacade.linkStreams$, []);
  const [assistants] = useObservable(roomFacade.assistants$, []);
  const [ui_muted] = useObservable(roomFacade.ui_muted$, false);
  const [ui_debug] = useObservable(roomFacade.ui_debug$, false);
  const [ui_isFront] = useObservable(roomFacade.ui_isFront$, true);
  const [ui_mode] = useObservable(roomFacade.ui_mode$, "HD");
  const [ui_beauty] = useObservable(roomFacade.ui_beauty$, 5);
  const [ui_operation] = useObservable(roomFacade.ui_operation$, "");
  const [muteStatus] = useObservable(roomFacade.muteStatus$, 0);

  return [
    roomFacade,
    roomRole,
    roomStatus,
    type,
    ownerId,
    anchorId,
    assistants,
    liveStreams,
    linkStreams,
    ui_muted,
    ui_debug,
    ui_isFront,
    ui_mode,
    ui_beauty,
    ui_operation,
    muteStatus
  ];
}
